﻿#include "DeviceDemoAnyCAN.h"
#include "../PublicService/SettingData.h"

using namespace DeviceLayer;

DYNAMIC_CREATE(DeviceDemoAnyCAN)

DeviceDemoAnyCAN::DeviceDemoAnyCAN()
{

}

bool DeviceDemoAnyCAN::InitFromSettingData(const QString &path)
{
    //如果有多个CANHub，那么我们需要在配置文件里指定要用哪一个。否则，不需要以下代码，在class声明里使用auto_wired_device即可。
    //注意：DeviceCANHub对象和其他CAN设备对象，在SettingData.xml中的定义顺序，必须是DeviceCANHub对象在前，其他CAN对象在后。
    /*
    QString canHubObjName = GET_SETTING_STRING(path + "/CANHubName");
    if (canHubObjName.isEmpty())
    {
        LOGERR("DeviceDemoAnyCAN::InitFromSettingData", "未设置所使用的CANHub对象名");
        return false;
    }
    canHub = std::dynamic_pointer_cast<DeviceCANHub>(BusinessLayer::ContainerForDevice::instance[canHubObjName]);
    if (canHub == nullptr)
    {
        LOGERR("DeviceDemoAnyCAN::InitFromSettingData", "名称为:" + canHubObjName + "的DeviceCANHub对象不存在。");
        return false;
    }
    */
    //--------------------------------------------------

    id = GET_SETTING_INT(path + "/CANId");
    canHub->RegisterResponseCallback(id, std::bind(&DeviceDemoAnyCAN::OnDataReceived, *this, std::placeholders::_1));
    return true;
}

void DeviceDemoAnyCAN::OnDataReceived(const can_frame msg)
{

}

bool DeviceDemoAnyCAN::QueryData()
{
    return true;
}
